﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using GMap.NET;
using GMap.NET.MapProviders;
using GMap.NET.Projections;

namespace GisControl.MapProviders.BaiduMapProvider
{
    public class BaiduMapHybirdProvider : BaiduMapProviderBase
    {
        public static readonly BaiduMapHybirdProvider Instance;

        static readonly string UrlFormat = "http://online{0}.map.bdimg.com/tile/?qt=tile&x={1}&y={2}&z={3}&styles=sl&v={4}&udt=20140314";

        readonly Guid id = new Guid("AF522C29-9F94-4E9B-BDB3-346CD058AE7B");

        public override Guid Id
        {
            get { return id; }
        }

        public string CnName
        {
            get
            {
                return "百度混合地图";
            }
        }

        public override string Name
        {
            get
            {
                return "BaiduHybridMap";
            }
        }

        public string Version
        {
            get
            {
                return "039";
            }
        }

        static BaiduMapHybirdProvider()
        {
            Instance = new BaiduMapHybirdProvider();
        }

        public override PureImage GetTileImage(GPoint pos, int zoom)
        {
            try
            {
                string url = MakeTileImageUrl(pos, zoom, LanguageStr);
                return GetTileImageUsingHttp(url);
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        string MakeTileImageUrl(GPoint pos, int zoom, string language)
        {
            var num = (pos.X + pos.Y) % 4 + 1;
            string url = string.Format(UrlFormat, num, pos.X, pos.Y, zoom);
            return url;
        }

    }
}
